package com.pushtime.service.impl.search;

import com.alibaba.fastjson.JSONObject;
import com.pushtime.service.search.HadoopInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

@Service
@Transactional
public class HadoopInfoServiceImpl implements HadoopInfo {


    @Value("${application.webhdfs.url}")
    private String url;
    @Value("${application.webhdfs.path}")
    private String path;

    private static String HADOOP_COLLECT="/?op=GETCONTENTSUMMARY";

    private final RestTemplate restTemplate;

    public HadoopInfoServiceImpl(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }


    @Override
    public JSONObject getHadoopInfo() {

        ResponseEntity<String> entity = restTemplate.getForEntity(url + path + HADOOP_COLLECT, String.class);
        String body = entity.getBody();
        System.out.print(body);
        return null;
    }

}
